<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>编辑新品/临措计划</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="./lib/layui-v2.6.3/css/layui.css" media="all">
    <link rel="stylesheet" href="./css/public.css" media="all">
</head>
<body>
<div class="layuimini-container">
    <div class="layuimini-main">
        <form class="layui-form" action="">
            <input type="hidden" name="id">
            <div class="layui-form-item">
                <label class="layui-form-label">类型</label>
                <div class="layui-input-block">
                    <select name="type" lay-verify="required">
                        <option value="">请选择</option>
                        <option value="新品">新品</option>
                        <option value="临措">临措</option>
                    </select>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">项目编号</label>
                <div class="layui-input-block">
                    <input type="text" name="projectNumber" required lay-verify="required" placeholder="请输入项目编号" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">工程名称</label>
                <div class="layui-input-block">
                    <input type="text" name="engineeringName" required lay-verify="required" placeholder="请输入工程名称" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">采购订单号</label>
                <div class="layui-input-block">
                    <input type="text" name="orderNumber" required lay-verify="required" placeholder="请输入采购订单号" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">物料描述</label>
                <div class="layui-input-block">
                    <input type="text" name="description" required lay-verify="required" placeholder="请输入物料描述" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">需求数量</label>
                <div class="layui-input-block">
                    <input type="number" name="quantityRequired" required lay-verify="required" placeholder="请输入需求数量" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">状态</label>
                <div class="layui-input-block">
                    <select name="status" lay-verify="required">
                        <option value="">请选择</option>
                        <option value="0">未完成</option>
                        <option value="1">已完成</option>
                    </select>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button class="layui-btn" lay-submit lay-filter="edit">提交</button>
                    <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                </div>
            </div>
        </form>
    </div>
</div>
<script src="./lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
<script>
    layui.use(['form', 'jquery'], function () {
        var form = layui.form,
            $ = layui.jquery,
            layer = layui.layer;

        // 加载数据
        window.loadData = function (data) {
            $('input[name="id"]').val(data.id);
            $('input[name="projectNumber"]').val(data.projectNumber);
            $('input[name="engineeringName"]').val(data.engineeringName);
            $('input[name="orderNumber"]').val(data.orderNumber);
            $('input[name="quantityRequired"]').val(data.quantityRequired);
            // 设置计划类型下拉框
            $("select[name='type']").val(data.type);
            $("select[name='status']").val(data.status);
            form.render();
        };

        // 提交表单
        form.on('submit(edit)', function (data) {
            $.ajax({
                url: '/plan/new/update',
                type: 'POST',
                contentType: 'application/json',
                data: JSON.stringify(data.field),
                success: function (res) {
                    if (res.code === 0) {
                        layer.msg('更新成功');
                        // 关闭弹窗并刷新表格
                        var iframeIndex = parent.layer.getFrameIndex(window.name);
                        parent.layer.close(iframeIndex);
                        parent.location.reload();
                    } else {
                        layer.msg('更新失败：' + res.msg);
                    }
                },
                error: function () {
                    layer.msg('网络异常，请稍后再试');
                }
            });
            return false;
        });
    });
</script>
</body>
</html>
